package com.kgcx.system.rabbitmq.consumer;

import com.alibaba.fastjson.JSONObject;
import com.kgcx.common.rabbitmq.consts.QueueConst;
import com.kgcx.system.domain.MqFail;
import com.kgcx.system.service.MqFailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 订单取消时状态变更
 */
@Component
@RabbitListener(queues = QueueConst.MQ_FAIL)
public class MqFailConsumer {
    private static final Logger LOG = LoggerFactory.getLogger(MqFailConsumer.class);

    @Autowired
    private MqFailService mqFailService;

    @RabbitHandler
    public void mqFail(String json) {
        LOG.info("收到增加mq失败的MQ消息。\n" + json);

        MqFail mqFail = JSONObject.parseObject(json, MqFail.class);

        mqFailService.addMqFail(mqFail);
    }

}
